package com.apop.common.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;

public class OrderGenerator {

    private static final Random RANDOM = new Random();
    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");

    public static String generateOrderNumber() {
        // 获取当前时间的毫秒级时间戳
        String timestamp = LocalDateTime.now().format(DATE_TIME_FORMATTER);

        // 生成一个4位的随机数
        int randomPart = RANDOM.nextInt(10000);
        String randomPartStr = String.format("%04d", randomPart);

        // 生成一个2位的随机序列号
        int sequence = RANDOM.nextInt(100);
        String sequenceStr = String.format("%02d", sequence);

        // 拼接成最终的订单号
        return timestamp + randomPartStr + sequenceStr;
    }

}
